﻿//JS操作cookies方法!
//写cookies
function setCookie(value, name, key) {
    var Days = 2;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    if (key == null || key == "") {
        document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/";
    }
    else {
        var nameValue = getCookie(name);
        if (nameValue == "") {
            document.cookie = name + "=" + key + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/";
        }
        else {
            var keyValue = getCookie(name, key);
            if (keyValue != "") {
                nameValue = nameValue.replace(key + "=" + keyValue, key + "=" + encodeURI(value));
                document.cookie = name + "=" + nameValue + ";expires=" + exp.toGMTString() + ";path=/";
            }
            else {
                document.cookie = name + "=" + nameValue + "&" + key + "=" + encodeURI(value) + ";expires=" + exp.toGMTString() + ";path=/";
            }
        }
    }
}
//读取cookies
function getCookie(name, key) {
    var nameValue = "";
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        nameValue = decodeURI(arr[2]);
    }
    if (key != null && key != "") {
        reg = new RegExp("(^| |&)" + key + "=([^(;|&|=)]*)(&|$)");
        if (arr = nameValue.match(reg)) {
             return decodeURI(arr[2]);
        }
        else return "";
    }
    else {
        return nameValue;
    }
}
//删除cookies
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();  
}


function getQueryString(queryName) {
/// <summary>
///  adfasdfsda
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
    var queryValue = "";
    var queryFound = false;
    if (window.location.search != "") {
        var search = window.location.search;
        var i = 0;
        while (i <= search.length) {
            start = i;
            end = start + queryName.length;
            if (search.substring(start, end) == queryName) {
                queryFound = true;
                break;
            }
            i++;
        }
        if (queryFound) {
            start = end + 1;
            end = search.indexOf("&", start);
            if (end < start)
                end = search.length;
            var getvalue = search.substring(start, end);
            return unescape(getvalue);
        }
    }
    return queryValue;
}